package com.mtiiot.fstcpserver.mq.kafka.pool;

import com.mtiiot.fstcpserver.mq.kafka.util.KafkaProperties;
import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

import java.util.List;
import java.util.Properties;

/**
 * Created by Administrator on 2016/7/26.
 */
public class KafkaProducerApp {
    private Producer<String, String> producer;
    private static ProducerConfig config;

    static {
        Properties ex = KafkaProperties.properties;
        config = new ProducerConfig(ex);
    }

    public KafkaProducerApp() {
        this.producer = new Producer(config);
    }

    public void sendData(String code, String msgKey, String msg) {
        KeyedMessage message = new KeyedMessage(code,msgKey , msg);
        this.producer.send(message);
    }

    public void sendDatas(List<KeyedMessage<String,String>> list) throws Exception{
        this.producer.send(list);
    }

    public void shutdown() {
        this.producer.close();
    }

}
